package com.usian.wemedia.controller;

import com.alibaba.fastjson.JSON;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmNews;
import com.usian.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.SuccessCallback;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2023/8/30 15:10
 */@RestController
@RequestMapping("/wmnews")
public class WmNewsController {

     @Autowired
    WmNewsService wmNewsService;

     @Autowired
     KafkaTemplate kafkaTemplate;


     @RequestMapping("/fabu")
     public ResponseResult fabu(Integer newsId){
         WmNews wmNews = wmNewsService.getById(newsId);
         ListenableFuture future = kafkaTemplate.send("usian-leadnews", JSON.toJSON(wmNews));
         future.addCallback(new SuccessCallback() {
                                @Override
                                public void onSuccess(Object result) {

                                }
                            },
                 new FailureCallback() {
                     @Override
                     public void onFailure(Throwable ex) {

                     }
                 });

         return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);

     }
}
